package com.thundersoft.phonecontact;

import android.content.Context;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import com.thundersoft.phonecontact.callFragments.CallListFragment;

import java.util.ArrayList;
import java.util.List;


public class SectionsPagerAdapter extends FragmentPagerAdapter {

    private static List<Fragment> fragmentList;
    private Context mContext;

    public SectionsPagerAdapter(FragmentManager fm, Context context) {
        super(fm);
        if (fragmentList == null) {
            fragmentList = new ArrayList<>();
            /*
        0:所有通讯记录
        1:未接来电
        2:已接来电
         */
            fragmentList.add(CallListFragment.newInstance(0));
            fragmentList.add(CallListFragment.newInstance(1));
            fragmentList.add(CallListFragment.newInstance(2));
        }
        mContext = context;
    }

    @Override
    public Fragment getItem(int position) {
        // getItem is called to instantiate the fragment for the given page.
        // Return a PlaceholderFragment (defined as a static inner class below).

        return fragmentList.get(position);
//        return PlaceholderFragment.newInstance(position);
    }

    @Override
    public int getCount() {
        return fragmentList.size();
    }

    @Override
    public CharSequence getPageTitle(int position) {
        switch (position) {
            case 0:
                return mContext.getString(R.string.tab_all_records);
            case 1:
                return mContext.getString(R.string.tab_missed_records);
            case 2:
                return mContext.getString(R.string.tab_received_records);
        }
        return null;
    }
}
